package online.hxstart.code.java8.chapter04;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import online.hxstart.code.java8.chapter04.Dish.Type;

/**
 * @author huxing
 * @date 2019/6/21 星期五 16:24
 * @describe 流处理测试
 */
public class StreamTest {

  public static void main(String[] args) {
    //

    List<Dish> menu = Arrays.asList(new Dish("pork", false, 800, Type.MEAT),
        new Dish("beff", false, 700, Type.MEAT),
        new Dish("chicken", false, 400, Dish.Type.MEAT),
        new Dish("french fries", true, 530, Dish.Type.OTHER),
        new Dish("rice", true, 350, Dish.Type.OTHER),
        new Dish("season fruit", true, 120, Dish.Type.OTHER),
        new Dish("pizza", true, 550, Dish.Type.OTHER),
        new Dish("prawns", false, 300, Dish.Type.FISH),
        new Dish("salmon", false, 450, Dish.Type.FISH));

    List<String> threeHighCaloric = menu.stream().filter(dish -> dish.getCalories() > 300)
        .map(Dish::getName).limit(3).collect(
            Collectors.toList());
    System.out.println(threeHighCaloric);

    List<String> names = new ArrayList<>();

    for (Dish s : menu) {
      names.add(s.getName());
    }

    Iterator<Dish> iterator = menu.iterator();

    while (iterator.hasNext()) {
      Dish dish = iterator.next();
      names.add(dish.getName());
    }
  }
}
